package com.fms.controller;

import com.fms.result.ResultData;
import com.fms.entity.Product;
import com.fms.service.ProductService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/product")
@RequiredArgsConstructor
public class ProductController {
    private final ProductService productService;

    //useless
    @GetMapping("/productList")
    public ResultData getProductList(){
        List<Product> productList = productService.getProductList();
        return ResultData.success(productList);
    }

    @PostMapping("/addProduct")
    public ResultData addProduct(@RequestBody Product product){
        System.out.println(product);
        String s = productService.addProduct(product);
        return ResultData.success(s);
    }

    @PostMapping("/deleteProduct/{id}")
    public ResultData deleteProduct(@PathVariable("id") String id){
        String message = productService.deleteProduct(id);
        return ResultData.success(message);
    }

    @PostMapping("/deleteProduct")
    public ResultData deleteProducts(@RequestBody Product[] products){
        String message = productService.deleteProducts(products);
        return ResultData.success(message);
    }
}
